package com.water.devtool;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.watermud.util.StringUtil;
import com.watermud.util.db.DBUtil;

public class TableUtil extends BaseTableUtil implements ITableUtil {

	public static String columnSql = "select c.*,m.COMMENTS COLUMN_COMMENT from cols c ,USER_COL_COMMENTS m "
			+ "where c.table_name = ? and  m.TABLE_NAME =c.table_name and m.COLUMN_NAME = c.COLUMN_NAME order by column_id";

	public static String tabComSql = "SELECT * FROM USER_TAB_COMMENTS WHERE TABLE_NAME=?";

	public List getAllTable() {
		String owner = ConfUtil.getValue("dbUser");
		if (StringUtil.isNull(owner)) {
			return new ArrayList();
		}
		String sql = "select * from all_tab_comments WHERE owner = ?  AND TABLE_TYPE = 'TABLE' and  SUBSTR(table_name,1,4) !='BIN$'   ";
		return DBUtil.queryForList(sql, new Object[] { owner }, HashMap.class);
	}

	public List getAllColumn(String table) {
		return DBUtil.queryForList(columnSql, new Object[] { table }, HashMap.class);
	}

	@Override
	public String getTableComment(String table) {
		return DBUtil.queryForString(tabComSql, new Object[] { table });
	}

}
